#include "../includes/need-a-name.hh"
#include "includes/sound-wave.hh"
#include <map>

SoundWave::SoundWave(){
  phynumber = 1+gridsetting::dimension;
  physical_variable_name.push_back("density");
  if(gridsetting::dimension>=1)
    physical_variable_name.push_back("velo_1");
  if(gridsetting::dimension>=2)
    physical_variable_name.push_back("velo_2");
  if(gridsetting::dimension==3)
    physical_variable_name.push_back("velo_3");    
  // TODO: transmit needs improvement
  transmit_equ_parameter();
  append_parameter("u0",0.0);
  append_parameter("v0",0.0);
  append_parameter("w0",0.0);
  append_parameter("rho0",0.0);
  append_parameter("k0",0.0);
}

SoundWave::~SoundWave(){
}

void SoundWave::get_equation_flux(int dim, double* dir, double* var, double* fequ){
  for(int tmpi=0; tmpi<memory::phynumber; tmpi++)
    fequ[tmpi]=0.0;  
  if(dim==1)
    get_1d_fx(fequ,var);
  if(dim==2){
    if(std::abs(dir[0])==1.0)
      get_2d_fx(fequ,var);
    if(std::abs(dir[1])==1.0)
      get_2d_fy(fequ,var);
  }
  if(dim==3){
    if(std::abs(dir[0])==1.0)
      get_3d_fx(fequ,var);
    if(std::abs(dir[1])==1.0)
      get_3d_fy(fequ,var);
    if(std::abs(dir[2])==1.0)
      get_3d_fz(fequ,var);
  }
}

void SoundWave::get_local_vmax(int index){
  int dim = gridsetting::dimension;
  // memory::local_vmax[index] = std::sqrt(para["k0"]*para["rho0"]);
  memory::local_vmax[index] = para["k0"]*para["rho0"]*2.0;  
  // if(dim==1)
  //   memory::local_vmax[index] = para["u0"];
  // if(dim==2)
  //   memory::local_vmax[index] = std::sqrt(std::pow(para["u0"],2)+std::pow(para["v0"],2));
  // if(dim==3)
  //   memory::local_vmax[index] = std::sqrt(std::pow(para["u0"],2)+std::pow(para["v0"],2)+std::pow(para["w0"],2)); 
  
}

void SoundWave::get_1d_fx(double* fequ, double* var){
  fequ[0] = para["u0"]      *var[0]+para["k0"]*var[1];
  fequ[1] = 1.0/para["rho0"]*var[0]+para["u0"]*var[1];  
}
void SoundWave::get_2d_fx(double* fequ, double* var){
  fequ[0] = para["u0"]      *var[0]+para["k0"]*var[1];
  fequ[1] = 1.0/para["rho0"]*var[0]+para["u0"]*var[1];
  fequ[2] =                         para["u0"]*var[2];      
}
void SoundWave::get_2d_fy(double* fequ, double* var){
  fequ[0] = para["v0"]      *var[0]+para["k0"]*var[2];
  fequ[1] =                         para["v0"]*var[1];
  fequ[2] = 1.0/para["rho0"]*var[0]+para["v0"]*var[2];  
}
void SoundWave::get_3d_fx(double* fequ, double* var){
  fequ[0] = para["u0"]      *var[0]+para["k0"]*var[1];
  fequ[1] = 1.0/para["rho0"]*var[0]+para["u0"]*var[1];
  fequ[2] =                         para["u0"]*var[2];
  fequ[3] =                         para["u0"]*var[3];
}
void SoundWave::get_3d_fy(double* fequ, double* var){
  fequ[0] = para["v0"]      *var[0]+para["k0"]*var[2];
  fequ[1] =                         para["v0"]*var[1];
  fequ[2] = 1.0/para["rho0"]*var[0]+para["v0"]*var[2];
  fequ[3] =                         para["v0"]*var[3];    
}
void SoundWave::get_3d_fz(double* fequ, double* var){
  fequ[0] = para["w0"]      *var[0]+para["k0"]*var[3];
  fequ[1] =                         para["w0"]*var[1];
  fequ[2] =                         para["w0"]*var[2];
  fequ[3] = 1.0/para["rho0"]*var[0]+para["w0"]*var[3];
}
